package insertionSort;

import shared.MyComparable;
import shared.MyStop;
import shared.SortInput;
import shared.SortInputVisitor;

/**
 * The {@link ConcreteInputProcessor} class is a concrete {@link InputProcessor}.
 */
public class ConcreteInputProcessor<T extends Comparable<? super T>> extends InputProcessor<T>{

	public ConcreteInputProcessor() {
		new Thread(this).start();
	}
	@Override
	public void run() {
		
		while(!this.isDone()){
			final SortInput<T> input = this.getInputBuffer().get();
			input.accept(new SortInputVisitor<T>() {

				@Override
				public void visit(final MyComparable<T> myComparable) {
					ConcreteInputProcessor.this.setState(new ReceivedInput<T>(myComparable.getComparable()));
				}

				@Override
				public void visit(final MyStop<T> myStop) {
					setResultFromState();
				}
			});
		}
	}

}
